package Demo1;
abstract class Animal{
    public String name;

    public Animal(String name){
        this.name = name;
    }
}
interface IRunning{//这里不可以为一个类，因为JAVA不支持多继承
    public void run();
}
interface ISwimming{//=================注意！！！——获得一个接口！！！=============
    public void swim();
}
interface IFly{
    public void fly();
}
class Dog extends Animal implements IRunning{//不可以先实现接口再继承。有先后顺序
    public Dog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "正在用四条狗腿跑！");
    }
}
class Fish extends Animal implements ISwimming{//=======注意！！！将接口的一端插在一个类上！！！=======
    public Fish(String name) {
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(name + "正在游泳！");
    }
}
class Bird extends Animal implements IFly{
    public Bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(name + "正在用翅膀飞！");
    }
}
class Duck extends Animal implements IRunning,IFly,ISwimming{
    public Duck(String name) {//这是一个构造方法，当实例化对象时会被调用
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "这只鸭子正在跑！");
    }

    @Override
    public void swim() {
        System.out.println(name + "这只鸭子正在游泳！");
    }

    @Override
    public void fly() {
        System.out.println(name + "这只鸭子正在飞！");
    }
}
class Robot implements IRunning{
    @Override
    public void run() {
        System.out.println("机器人再用机器腿跑步！！！");
    }
}
public class Test {
    //实现了IRunning接口的都可以接收
    public static void walk(IRunning iRunning){//使用walk这个方法连上了IRunning这个接口
        iRunning.run();
    }
    public static void swim(ISwimming iSwimming){//=====注意！！！接口的另一端插在这个方法上！！！通过访问这个方法就能间接访问那个类=======
        iSwimming.swim();
    }
    public static void main(String[] args) {//这里是实现接口连着的内容的地方
        walk(new Dog("旺财"));//狗类实现了IRunning这个接口，连接上这个接口后就可以调用狗类中的成员方法“run”
        walk(new Duck("扁嘴儿"));//鸭类实现了IRunning这个接口，可调用
        swim(new Fish("鱼摆摆"));
        swim(new Duck("鸭游游"));
        walk(new Robot());
    }
}
